package cn.b.sky.user.service.impl;

import cn.b.sky.user.dao.ECodeDao;
import cn.b.sky.user.service.ECodeService;
import cn.b.sky.user.service.model.ECode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName: ECodeServiceImpl 
 * @Description:枚举码操作实现类 
 * @author: ZhaoXin
 * @date: 2015-7-27 上午10:34:34
 * @version: V1.0  
 *
 */
@Service("eCodeService")
public class ECodeServiceImpl implements ECodeService {

  @Autowired
  private ECodeDao eCodeDao;

  @Override
  public List<ECode> selectECodeList(String eCodeType, String languageCode) {
    if (!StringUtils.isEmpty(eCodeType)) {
      return eCodeDao.selectECodeList(eCodeType, languageCode);
    } else {
      return null;
    }
  }

  @Override
  public ECode selectEcodeByECodeTypeAndLanguageCodeAndECode(String ecode, String eCodeType, String languageCode) {
    if (StringUtils.isEmpty(ecode)) {
      return null;
    }
    return eCodeDao.selectEcodeByECodeTypeAndLanguageCodeAndECode(ecode, eCodeType, languageCode);
  }

  @Override
  public Map<String, ECode> selectECodeMap(String eCodeType, String languageCode) {
    List<ECode> ecodeList = this.selectECodeList(eCodeType, languageCode);
    Map<String, ECode> ecodeMap = new HashMap<String, ECode>(ecodeList.size());
    for (ECode ecode : ecodeList) {
      ecodeMap.put(ecode.geteCode(), ecode);
    }
    return ecodeMap;
  }

}
